Introduction
We are going to reproduce three different plots, of which we are only given the data set and the final image file. Each of them has two versions:
- The first version is a plot made just using the layer functions of
ggplot2and leaving everything else with the defaults. This is, usingggplot,geom_*,stat_*andannotate_*functions (click on the image to see it bigger).
- The second version builds from the first plot to create a more
complex display with customized
scales_*,coord_*,facet_*ortheme_*. Helper functions such aslabs()orguides()could also be used (click on the image to see it bigger).
: ggplot2 will
automatically load all three data sets used in this practical.
Organization of the practical
You will see different icons through the document, the meaning of which is:
: additional or useful
information
: a worked example
: a practical exercise
: a space to answer the exercise
: a hint to solve an exercise
: a more challenging exercise
Simple versions
Plot 2
Need help with the count numbers shown in each stacked bar? https://stackoverflow.com/questions/6644997/showing-data-values-on-stacked-bar-chart-in-ggplot2
Answer:
Complex versions
Plot 1
Answer:
Plot 2
Answer:
This graph uses a
scale_fill_brewer palette, can you find which one?
Plot 3
Answer:
This graph uses a
scale_fill_brewer palette, can you find which one?